package com.qf;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ZSetOperations;
import org.springframework.test.context.junit4.SpringRunner;

import java.util.Iterator;
import java.util.Set;

@RunWith(SpringRunner.class)
@SpringBootTest
public class test3 {

    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Test
    public void demo01(){
        redisTemplate.opsForZSet().add("score","tom",22);
        redisTemplate.opsForZSet().add("score","jim",45);
        redisTemplate.opsForZSet().add("score","nun",32);
        redisTemplate.opsForZSet().add("score","lily",64);

        System.out.println(redisTemplate.opsForZSet().rangeWithScores("score", 0, -1));
        System.out.println(redisTemplate.opsForZSet().score("score", "tom"));
        Set<ZSetOperations.TypedTuple<String>> set = redisTemplate.opsForZSet().rangeByScoreWithScores("score", 0, 100);
        for (ZSetOperations.TypedTuple<String> o : set) {
            System.out.println(o.getValue()+"---->"+o.getScore());
        }
        System.out.println("============================");

        redisTemplate.opsForSet().add("name","jim","jim1","jim2","jim3","jim4","jim5");
        System.out.println(redisTemplate.opsForSet().members("name"));
        System.out.println("=============================");
        redisTemplate.opsForList().leftPushAll("name3","tom","tom2","tom3","tom4","tom5");
        System.out.println(redisTemplate.opsForList().range("name2",0,-1));
        System.out.println(redisTemplate.opsForList().range("name3",0,-1));
        System.out.println("=============================");
        redisTemplate.opsForHash().put("pig","color","black");
        redisTemplate.opsForHash().put("pig","height","2");
        redisTemplate.opsForHash().put("pig","sex","0");

        System.out.println(redisTemplate.opsForHash().entries("pig"));


    }


}
